<template>
  <div class="conte">
    <el-table
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      style="width: 100%"
    >
      <el-table-column prop="admin_id" label="id" width="180">
      </el-table-column>
      <el-table-column prop="admin_name" label="用户名" width="180">
      </el-table-column>
      <el-table-column prop="pw" label="密码"> </el-table-column>
      <el-table-column prop="pw" label="删除/禁用">
        <template slot-scope="scope">
          <el-button
            type="danger"
            icon="el-icon-delete"
            @click="Delete(scope.$index)"
          >
          </el-button>
          <el-button
            v-show="
              tableData[currentPage * pageSize - (pageSize - scope.$index)]
                .status == 1
            "
            type="primary"
            @click="forbid(scope.$index)"
            ><a>禁用</a></el-button
          >
          <el-button
            v-show="
              tableData[currentPage * pageSize - (pageSize - scope.$index)]
                .status == 3
            "
            type="primary"
            @click="forbid(scope.$index)"
            ><a>已禁用</a></el-button
          >
        </template>
      </el-table-column>
      >
    </el-table>
    <div class="block" style="margin-top: 15px">
      <el-pagination
        align="center"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[1, 5, 10, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.length"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      token: "",
      tableData: [],
      currentPage: 1, // 当前页码
      total: 20, // 总条数
      pageSize: 5, // 每页的数据条
    };
  },
  mounted() {
    console.log(this.$store.state.token);
    this.init();
  },
  methods: {
    init() {
      this.axios({
        method: "post",
        url: "http://api_devs.wanxikeji.cn/api/admin/accountList",
        data: {
          token: this.$store.state.token,
          size: "1000",
          page: "1",
        },
      }).then((res) => {
        this.tableData = res.data.data.data.reverse();
      });
    },
    Delete(val) {
      this.axios({
        method: "post",
        url: "http://api_devs.wanxikeji.cn/api/admin/accountDelete",
        data: {
          token: this.$store.state.token,
          id: this.tableData[
            this.currentPage * this.pageSize - (this.pageSize - val)
          ].admin_id,
        },
      }).then((res) => {
        console.log(res);
        this.init();
      });
    },
    forbid(val) {
      this.axios({
        method: "post",
        url: "http://api_devs.wanxikeji.cn/api/admin/accountBan",
        data: {
          token: this.$store.state.token,
          id: this.tableData[
            this.currentPage * this.pageSize - (this.pageSize - val)
          ].admin_id,
        },
      }).then((res) => {
        console.log(res);
        this.init();
      });
    },
    //每页条数改变时触发 选择一页显示多少行
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.currentPage = 1;
      this.pageSize = val;
    },
    //当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
  },
};
</script>

<style  scoped>
.conte {
  background: white;
  height: 100%;
  padding-top: 20px;
}
</style>>


